﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using dotsoftRAID_Controller.RAIDControllers;

namespace dotsoftRAID_Controller
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "dotsoftRAID Controller";

            //Save all output to a log file
            OutputToLogFile();

            //Initialize RAID Controllers
            InitializeRAIDControllers();

            Console.ReadLine();
        }

        private static void OutputToLogFile()
        {
            Console.SetOut(Logging.Initialize());
        }

        private static void InitializeRAIDControllers()
        {
            Logging.EnterMethod();
            foreach (ConfigurationItem raid in Configuration.Load())
            {
                switch (raid.Type)
                {
                    case ConfigurationItem.RAID_TYPE.RAID1:
                        RAID raid1 = new RAID1(raid.dev0, raid.dev1);
                        raid1.Process += RAID_Process;
                        raid1.Initialize();
                        break;
                    case ConfigurationItem.RAID_TYPE.RAID5:
                        RAID raid5 = new RAID5(raid.dev0, null);
                        raid5.Process += RAID_Process;
                        raid5.Initialize();
                        break;
                    case ConfigurationItem.RAID_TYPE.RAID10:
                        RAID raid10 = new RAID10(raid.dev0, null);
                        raid10.Process += RAID_Process;
                        raid10.Initialize();
                        break;
                }
            }
            Logging.ExitMethod();
        }

        private static void RAID_Process(string message)
        {
            Console.WriteLine(message);
        }
    }
}
